Ext.namespace("Ext.milan.pagejs.organization.page_orgpubdatamanage");


Ext.milan.pagejs.organization.page_orgpubdatamanage.docLoadBeforeCallBack = function() {
};

Ext.milan.pagejs.organization.page_orgpubdatamanage.docOnReadyCallback = function() 
{alert('3');
	Ext.milan.pagejs.organization.page_orgpubdatamanage.deptTree = new dhtmlXTreeObject("_pubdata_tree","100%","100%",0);
	var deptTree = Ext.milan.pagejs.organization.page_orgpubdatamanage.deptTree;
	deptTree.setImagePath(Milan.skinType+"images/dhtmlx/tree/csh_vista/");
	deptTree.setDataMode("json");
	deptTree.loadJSON("pubData/tree.do");
	
	deptTree.attachEvent("onXLE",function(){
		var form = $("orgDepartmentListFormId");
		$("_pubdata_tree").removeChild($("holdinfo"));
		if(form.deptID.value == -1){
			var firstId = deptTree.getItemIdByIndex(0,0);
			var firstDeptId = deptTree.getUserData(firstId,"id");
			deptTree.selectItem("DPT"+firstDeptId,true);
			deptTree.openItem("DPT"+firstDeptId);
		}else{
			deptTree.selectItem("DPT"+form.deptID.value,true);
			deptTree.openItem("DPT"+form.deptID.value);
		}
	});
	deptTree.attachEvent("onClick", function(treeItemID,previouslyItemID){   
		var form = $("orgDepartmentListFormId");
		
		$("dptName").innerHTML = deptTree.getItemText(treeItemID);
		$("parentDptName").innerHTML = deptTree.getItemText(deptTree.getParentId(treeItemID));
		$("dptSortNO").innerHTML = deptTree.getUserData(treeItemID,"sortNO");
		$("dptMemo").innerHTML = deptTree.getUserData(treeItemID,"memo");
		
		var tmpID = treeItemID;
		var deptPath = "";
		while (tmpID!="0")
		{
			deptPath = deptTree.getItemText(tmpID)+"-"+deptPath;
			tmpID = deptTree.getParentId(tmpID);
		}
		deptPath = deptPath.substring(0,deptPath.length-1);
		$("dptPath").innerHTML = deptPath;
		form.deptID.value= deptTree.getUserData(treeItemID,"id");
		form.deptName.value = deptTree.getItemText(treeItemID);
		form.parentDeptID.value = deptTree.getUserData(deptTree.getParentId(treeItemID),"id");
		form.parentDeptID1.value = deptTree.getUserData(deptTree.getParentId(treeItemID),"id");
		
			$("btnAdd2").style.display = "";
			$("btnEdit").style.display = "";
			//$("btnPermission").style.display = "";
			//$("btnClear").style.display = "";
		
		if (!deptTree.getParentId(treeItemID) || deptTree.getUserData(deptTree.getParentId(treeItemID),"id")==0)
		{
			$("btnCopy").style.display = "none";
			$("btnMove").style.display = "none";
			//$("btnDel").style.display = "none";
		}
		else
		{
			$("btnAdds").style.display = "";
			$("btnCopy").style.display = "";
			$("btnMove").style.display = "";
			//$("btnDel").style.display = "";
			
		}
	});
};


Ext.milan.pagejs.organization.page_orgpubdatamanage.refreshTree = function(showID)
{
	Ext.milan.pagejs.organization.page_orgpubdatamanage.deptTree.selectItem("DPT"+showID,true);

	/*Milan.ajaxutility.formSubmit(
	{
		url : "pubdataAction.do?actionType=7&showid=" + showid,
		success : function(response,option)
		{
			$("org_pubdata_leftFrame").update(response.responseText);
		}
	});*/
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.updateDepartmentInfo = function()
{
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.refreshView = function(deptid, parentid)
{
	var url = "pubdataAction.do?actionType=5&parentdeptid=" + parentid + "&deptid=" + deptid;
	Milan.ajaxutility.updateContentUseAjax("POST", url, "org_pubdata_rightFrame");
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.showAddSameLv = function(deptid)
{
	var form = $("orgDepartmentListFormId");
	var pid = form.parentDeptID1.value;
	if(pid == "undefined"){
		pid = "";
	}
    var url = "dept/create.do?pid=" + pid;
    win = Milan.commonutils.createModelPop(
    {
        title: "新建同级部门",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.showAddTopLv = function()
{
	var form = $("orgDepartmentListFormId");
    var url = "dept/pubdataActiontype6.jsp?actionType=6&parentDeptID=0&deptid=0";
    win = Milan.commonutils.createModelPop(
    {
        title: "新建部门",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.showAddSubLv = function(deptid)
{
	var form = $("orgDepartmentListFormId");
    var url = "dept/create.do?pid=" + form.deptID.value;
    win = Milan.commonutils.createModelPop(
    {
        title: "新建下级部门",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);	
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.showUpdatePage = function()
{
	var form = $("orgDepartmentListFormId");
    var url = "dept/edit.do?deptid=" + form.deptID.value;
    win = Milan.commonutils.createModelPop(
    {
        title: "编辑部门信息",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.showCopyPage = function()
{
	var form = $("orgDepartmentListFormId");
    var url = "dept/copy.do?&deptid=" + form.deptID.value;
    win = Milan.commonutils.createModelPop(
    {
        title: "复制部门",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.showMovePage = function()
{
	var form = $("orgDepartmentListFormId");
    var url = "dept/move.do?deptid=" + form.deptID.value;
    win = Milan.commonutils.createModelPop(
    {
        title: "移动部门",
		height: "400px",
		width : "600px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.showClearPage = function()
{
	var form = $("orgDepartmentListFormId");
    var url = "dept/pubdataActiontype13.jsp?actionType=13&deptID=" + form.deptID.value;
    win = Milan.commonutils.createModelPop(
    {
        title: "选择清空方式",
		height: "400px",
		width : "350px"
    });
    Milan.ajaxutility.updateContentUseAjax("post",url,win);
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.showSetPermissionPage = function(deptID)
{ 
	var form = $("orgDepartmentListFormId");
    var url = "dept/checkPer.do?deptid=" + form.deptID.value;
	Milan.pagejs.page_index.updateCurrentTabByUrl(url);
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.deleteDept = function(deptName, showid)
{
	var form = $("orgDepartmentListFormId");
    new Milan.widget.ConfirmDialog("确认信息", "确认要删除部门[" + deptName + "]吗?", 
    {
    	confirmCallback : function(){
			Milan.ajaxutility.formSubmit(
            {
                url: "dept/delete.do",
				params: "deptid=" + form.deptID.value,
				success : function(response, option)
				{
					Ext.milan.pagejs.organization.page_orgpubdatamanage.deptTree.deleteItem("DPT"+form.deptID.value,true);
					//Ext.milan.pagejs.organization.page_orgpubdatamanage.refreshTree(showid);
					//Ext.milan.pagejs.organization.page_orgpubdatamanage.refreshView(showid, response.responseText);
					
				}
            });
		},
		cancelCallback : function(){}
    });
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.validateForm = function(form)
{
	if (form.deptname.value.trim()=="")
	{
		new Milan.widget.Dialog("输入提示", "部门名称 不能为空!");
		return false;
	}
	if (form.sortno.value.trim()=="")
	{
		new Milan.widget.Dialog("输入提示", "部门序号 不能为空!");
		return false;
	}
	if (!Milan.string.isValidText(form.deptname.value,"!@#$%^&*+|=?';:\"",true)) 
	{
		new Milan.widget.Dialog("输入提示", "部门名称含有非法字符!");
		return false;
	}
	if(form.deptname.value.trim().length>30)
	{
	    new Milan.widget.Dialog("输入提示", "部门名称必须在30个字符以内!");
		return false;
	}
	if (!Milan.string.isNumber(form.sortno.value.trim()))
	{
		new Milan.widget.Dialog("输入提示", "部门序号有效输入为0~99之间的数字!");
		return false;
	}
	if (form.memo.value.length > 200)
	{
		new Milan.widget.Dialog("输入提示", "请输入少于200字符的备注！");
		return false;
	}
	return true;    
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.addDept = function()
{
	var form = $("addOrgDepartmentFormId");
	if (!Ext.milan.pagejs.organization.page_orgpubdatamanage.validateForm(form))
		return;
	Milan.ajaxutility.formSubmit(
    {
        form: "addOrgDepartmentFormId",
        success: function(response){
			var XMLDoc = response.responseXML;
			var deptID = XMLDoc.getElementsByTagName("param")[0].firstChild.nodeValue;
			var deptTree = Ext.milan.pagejs.organization.page_orgpubdatamanage.deptTree;
			deptTree.insertNewChild("DPT"+form.pid.value,"DPT"+deptID,form.deptname.value);
			deptTree.setUserData("DPT"+deptID,"id",deptID);
			deptTree.setUserData("DPT"+deptID,"sortNO",form.sortno.value);
			deptTree.setUserData("DPT"+deptID,"memo",form.memo.value);
			deptTree.selectItem("DPT"+deptID,true);
			win.closeDialog();
		}
    });
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.updateDept = function(parentid)
{
	var form = $("updateOrgDepartmentFormId");
	if (!Ext.milan.pagejs.organization.page_orgpubdatamanage.validateForm(form))
		return;
	Milan.ajaxutility.formSubmit(
    {
        form: "updateOrgDepartmentFormId",
        success: function(){
			var form = $("updateOrgDepartmentFormId");
			var deptID = form.deptid.value;
			var deptTree = Ext.milan.pagejs.organization.page_orgpubdatamanage.deptTree;

			deptTree.setItemText("DPT"+deptID,form.deptname.value);
			deptTree.setUserData("DPT"+deptID,"sortNO",form.sortno.value);
			deptTree.setUserData("DPT"+deptID,"memo",form.memo.value);
			deptTree.selectItem("DPT"+deptID,true);
			
			win.closeDialog();

		}
    });
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.copyDept = function()
{
	var form = $("copyOrgDepartmentFormId");
	if (!Ext.milan.pagejs.organization.page_orgpubdatamanage.validateForm(form))
		return;
	Milan.ajaxutility.formSubmit(
    {
        form: "copyOrgDepartmentFormId",
        success: function(response){
			var form = $("copyOrgDepartmentFormId");
			var XMLDoc = response.responseXML;
			var deptID = XMLDoc.getElementsByTagName("param")[0].firstChild.nodeValue;
			var deptTree = Ext.milan.pagejs.organization.page_orgpubdatamanage.deptTree;
			deptTree.insertNewChild("DPT"+form.parentdeptid.value,"DPT"+deptID,form.deptname.value);
			deptTree.setUserData("DPT"+deptID,"id",deptID);
			deptTree.setUserData("DPT"+deptID,"sortNO",form.sortno.value);
			deptTree.setUserData("DPT"+deptID,"memo",form.memo.value);
			deptTree.selectItem("DPT"+deptID,true);
			
			win.closeDialog();
			//Ext.milan.pagejs.organization.page_orgpubdatamanage.refreshTree(showid);
		}
    });
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.moveDept = function()
{
	var form = $("moveOrgDepartmentFormId");
	if(form.pid.value == form.deptid.value)
	{
	    new Milan.widget.Dialog("输入提示", "无法将本部门设为自身的上级部门，请重新选择!");
		return false;
	}
	if(form.pid.value == form.preparentdeptid.value)
	{
	    new Milan.widget.Dialog("输入提示", "移动后的上级部门与原上级部门一样，请重新选择!");
		return false;
	}
	Milan.ajaxutility.formSubmit(
    {
        form: "moveOrgDepartmentFormId",
        success: function(){
			var form = $("moveOrgDepartmentFormId");
			var parentID = form.parentdeptid.value;
			var deptTree = Ext.milan.pagejs.organization.page_orgpubdatamanage.deptTree;
			var deptID = form.deptid.value;
			deptTree.moveItem("DPT"+deptID,"item_child","DPT"+parentID);
			deptTree.selectItem("DPT"+deptID,true);
			
			win.closeDialog();
			
		}
    });
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.clearDept = function()
{
	var form = $("clearOrgDepartmentFormId");
    new Milan.widget.ComfirmDialog("确认信息", "确认要清空此部门?", 
    {
    	confirmCallback : function(){
			Milan.ajaxutility.formSubmit(
            {
                form : "clearOrgDepartmentFormId",
                success: function(){
                	win.closeDialog();
				}
            });
		},
		cancelCallback : function(){}
    });
}

/**
 * 选择部门
 */
Ext.milan.pagejs.organization.page_orgpubdatamanage.selectDept = function(formId)
{
	new Milan.widget.Selector({
		orgType:"32",
		title:"部门选择",
		deptUrl:"dept/selectDept.do?",
		quickSelectUrl:"dept/quickSelectDept.do?",
		searchUrl:"dept/selectDeptByDeptid.do?",
		isRecentEnable :false,
		isUpdateRecentEnable :false
	},
	false,
	{
		onSelectedCallBack : function(arr)
		{
	 		if (arr!=null)
	    	{
			    var form = $(formId);
	        	form.parentDeptName.value = arr[0].name;
		        form.parentdeptid.value = arr[0].deptid;
			}
		}
	});
	
/*
    Milan.showModalDialog("userAction.do?actionType=29", "选择部门", "dialogWidth:400pt;dialogHeight:300pt;help:0;status:0");
    Milan.showModalDialog.callback = function(arr)
    {
        if (arr!=null)
    	{
		    var form = $(formId);
        	form.parentDeptName.value = arr.name;
	        form.parentdeptid.value = arr.id;
		}
	}
*/
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.hideWin = function()
{
	if(win)
	    win.closeDialog()
}

Ext.milan.pagejs.organization.page_orgpubdatamanage.directoryPermission = function(deptid){
	var url = "directory/auth.do?authid=" + deptid+"&authType=2&dirType=2";
	win = Milan.commonutils.createModelPop({
		title:"目录权限",
		url:url,
		height: "600px",
		width : "320px"
	});
}